require(grDevices)
require(showtext)

args <- commandArgs(TRUE)

library(RColorBrewer)
library(showtext)
showtext_auto(enable=TRUE)

png("cpu-metrics.png", width=8000, height=2000)

data <- read.csv(args[1], sep=',', colClasses=c("numeric", "NULL", "NULL", "numeric", "numeric", "numeric", "numeric", "numeric"))

time <- data[,1]
ipc <- data[,2] * 100
llcm <- data[,3] / 10000
llc <- data[,4] / 10
mbl <- data[,5]
mbr <- data[,6]

plot.new()
plot.window(xlim=c(1,749), ylim=c(0, min(4000, max(llcm))), xaxs="i", yaxs="i")
title(xlab="time (s)", ylab="value")
legend("top", c("ipc (除以100)", "llc_misses (乘10000)", "llc (乘10)", "mbl", "mbr"), col=c("green", "red", "blue", "cyan", "black"), bty="n", lwd=2, cex=1.5, seg.len=c(8))
grid(40, 20)

lines(time, llcm, type="l", lwd=2, col="red")
lines(time, ipc, type="l", lwd=2, col="green")
lines(time, llc, type="l", lwd=2, col="blue")
lines(time, mbl, type="l", lwd=2, col="cyan")
lines(time, mbr, type="l", lwd=2, col="black")

axis(1, at=seq(1, 749, by=1), cex.axis=1)
axis(2, at=seq(1, 4000, by=10), cex.axis=1)
box()
dev.off()

